﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BaseReport.SQL;
using Newtonsoft.Json;
using Smt.Asm.Api.Helper;
using WebApiDemo.Models;

namespace WebApiDemo.Controllers
{
    public class TestServiceController : Controller
    {
        //
        // GET: /TestService/
        [HttpPost]
        [ActionName("getbackdata")]
        public string GetBackData()
        {
            var req = ParamHelper.GetRequestEntity<Person>();
            return "Test Data is  true!" + req.Name;
        }

        [HttpPost]
        [ActionName("getAllUser")]
        public string GetUsers()
        {
            var req = ParamHelper.GetRequestEntity<Person>();
            string Key = req.key;
            if (Key != "eba28190-0bd2-434b-82aa-0d57df73f8e6")
            {
                return "无效秘钥！";
            }
            var users = new BaseSql().GetUsers();
            string result = JsonConvert.SerializeObject(new
            {
                CurrentUsers=users.Select(
                c=>new
                {
                    id=c.Id,
                    name=c.Name,
                    msg=c.Msg
                }
                ).ToArray()
            });
            return result;
        }

    }
}
